package com.kws.payment.controller;

import com.google.gson.JsonObject;
import com.kws.common.core.domain.R;
import com.kws.payment.dao.RefundUnionPayRq;
import com.kws.payment.dao.UnionPayResultNotificationRq;
import com.kws.payment.dao.UnionPayRq;
import com.kws.payment.service.UnionPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <b>UnionH5PayController</b>
 *
 * @description: UnionH5PayController <br>
 * @date: 2024/11/27 16:53 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "银联H5支付")
@RestController
public class UnionH5PayController {
    private static final Logger logger = LoggerFactory.getLogger(UnionH5PayController.class);

    @Autowired
    private UnionPayService unionPayService;

    @ApiOperation("创建支付宝订单")
    @PostMapping("/alipay/createOrder")
    public R aliPayCreateOrder(@RequestBody UnionPayRq rq) throws Exception {
        return unionPayService.aliPayCreateOrder(rq);
    }

    @ApiOperation("创建微信支付订单")
    @PostMapping("/weixinPay/createOrder")
    public R weixinPayCreateOrder(@RequestBody UnionPayRq rq){
        return unionPayService.weixinPayCreateOrder(rq);
    }

    @ApiOperation("云闪付下单")
    @PostMapping("/unionPay/createOrder")
    public R unionPayCreateOrder(@RequestBody UnionPayRq rq){
        return unionPayService.unionPayCreateOrder(rq);
    }

    @ApiOperation("退款")
    @PostMapping("/refundOrder")
    public R refundOrder(@RequestBody RefundUnionPayRq rq) throws Exception {
        return unionPayService.refundOrder(rq);
    }

    @ApiOperation("取消订单")
    @PostMapping("/cancel/order")
    public R cancelOrder(@RequestBody UnionPayRq rq) throws Exception {
        return unionPayService.cancelOrder(rq);
    }

    @ApiOperation("支付结果通知")
    @PostMapping("/unionPay/resultNotification")
    public JsonObject unionPayResultNotification(@RequestBody UnionPayResultNotificationRq rq){
        JsonObject json = unionPayService.unionPayResultNotification(rq);
        return json;
    }

    @ApiOperation("退款结果通知")
    @PostMapping("/refund/resultNotification")
    public JsonObject refundResultNotification(@RequestBody UnionPayResultNotificationRq rq){
        JsonObject json = unionPayService.refundResultNotification(rq);
        return json;
    }
}
